package com.ai3d.rfid.common.log

import android.util.Log
import com.ai3d.rfid.BuildConfig

/**
 * @ProjectName : Trias
 * @Author : weijinsong
 * @Time : 2022/8/31 15:06
 * @Description : 文件描述
 */
object Logcat {
    const val TAG = "trias"
    private const val MAX_LENGTH = 4000

    @JvmStatic
    fun e(msg: String) {
        if (BuildConfig.DEBUG) {
            var index = 0
            var finalString: String
            while (index < msg.length) {
                finalString = if (msg.length <= index + MAX_LENGTH) {
                    msg.substring(index)
                } else {
                    msg.substring(index, MAX_LENGTH)
                }
                index += MAX_LENGTH
                Log.e(TAG, finalString)
            }
        }
    }

    @JvmStatic
    fun e(tag: String, msg: String?) {
        if (BuildConfig.DEBUG) {
            var index = 0
            var finalString: String
            while (index < msg?.length!!) {
                finalString = if (msg.length <= index + MAX_LENGTH) {
                    msg.substring(index)
                } else {
                    msg.substring(index, MAX_LENGTH)
                }
                index += MAX_LENGTH
                Log.e(tag, finalString)
            }
        }
    }

    @JvmStatic
    fun d(msg: String?) {
        if (BuildConfig.DEBUG) {
            var index = 0
            var finalString: String
            while (index < msg?.length!!) {
                finalString = if (msg.length <= index + MAX_LENGTH) {
                    msg.substring(index)
                } else {
                    msg.substring(index, MAX_LENGTH)
                }
                index += MAX_LENGTH
                Log.d(TAG, finalString)
            }
        }
    }

    @JvmStatic
    fun d(tag: String, msg: String?) {
        if (BuildConfig.DEBUG) {
            var index = 0
            var finalString: String
            while (index < msg?.length!!) {
                finalString = if (msg.length <= index + MAX_LENGTH) {
                    msg.substring(index)
                } else {
                    msg.substring(index, MAX_LENGTH)
                }
                index += MAX_LENGTH
                Log.d(tag, finalString)
            }
        }
    }

    @JvmStatic
    fun i(msg: String?) {
        if (BuildConfig.DEBUG) {
            var index = 0
            var finalString: String
            while (index < msg?.length!!) {
                finalString = if (msg.length <= index + MAX_LENGTH) {
                    msg.substring(index)
                } else {
                    msg.substring(index, MAX_LENGTH)
                }
                index += MAX_LENGTH
                Log.i(TAG, finalString)
            }
        }
    }

    @JvmStatic
    fun i(tag: String, msg: String?) {
        if (BuildConfig.DEBUG) {
            var index = 0
            var finalString: String
            while (index < msg?.length!!) {
                finalString = if (msg.length <= index + MAX_LENGTH) {
                    msg.substring(index)
                } else {
                    msg.substring(index, MAX_LENGTH)
                }
                index += MAX_LENGTH
                Log.i(TAG, finalString)
            }
        }
    }

}